home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / shadow-3.1.4 / sulog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-26  |  1.4 KB  |  71 lines

  1. /*
  2.  * Copyright 1989, 1990, 1991, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Permission is granted to copy and create derivative works for any
  6.  * non-commercial purpose, provided this copyright notice is preserved
  7.  * in all copies of source code, or included in human readable form
  8.  * and conspicuously displayed on all copies of object code or
  9.  * distribution media.
  10.  */
  11.  
  12. #include <sys/types.h>
  13. #include <stdio.h>
  14. #include <time.h>
  15. #ifndef    BSD
  16. #include <string.h>
  17. #include <memory.h>
  18. #else
  19. #include <strings.h>
  20. #define    strchr    index
  21. #define    strrchr    rindex
  22. #endif
  23. #include "config.h"
  24.  
  25. #ifndef    lint
  26. static    char    sccsid[] = "@(#)sulog.c    3.2    07:43:31    9/17/91";
  27. #endif
  28.  
  29. extern    char    name[];
  30. extern    char    oldname[];
  31.  
  32. time_t    time ();
  33. extern    char    *getdef_str();
  34.  
  35. void    sulog (success)
  36. int    success;
  37. {
  38.     char    *sulog;
  39.     char    *tty;
  40.     char    *cp;
  41.     char    *ttyname ();
  42.     time_t    clock;
  43.     struct    tm    *tm;
  44.     struct    tm    *localtime ();
  45.     FILE    *fp;
  46.  
  47.     if ( (sulog=getdef_str("SULOG_FILE")) == (char *) 0 )
  48.         return;
  49.  
  50.     if ((fp = fopen (sulog, "a+")) == (FILE *) 0)
  51.         return;            /* can't open or create logfile */
  52.  
  53.     (void) time (&clock);
  54.     tm = localtime (&clock);
  55.  
  56.     if (isatty (0) && (cp = ttyname (0))) {
  57.         if (tty = strrchr (cp, '/'))
  58.             tty++;
  59.         else
  60.             tty = cp;
  61.     } else
  62.         tty = "???";
  63.  
  64.     (void) fprintf (fp, "SU %.02d/%0.2d %.02d:%.02d %c %.6s %s-%s\n",
  65.         tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min,
  66.         success ? '+':'-', tty, oldname, name);
  67.  
  68.     fflush (fp);
  69.     fclose (fp);
  70. }
  71.